/**
 * Please modify this class to meet your needs
 * This class is not complete
 */

package com.cctv.esb._interface.sendmsgservicesubscribeservice._1_0;

import java.util.logging.Logger;
import java.util.Date;
import java.util.List;
import org.apache.commons.lang3.StringUtils;
import com.cctv.esb.schema.pubsub._1.ResponseType;
import com.cctv.mcs.schema.sendmsgservice._1.*;
import com.ctvit.common.EntityClassSet;
import com.ctvit.framework.web.context.ContextHolder;
import com.ctvit.sms.platform.domain.*;
import com.ctvit.sms.platform.service.ReqTaskService;

/**
 * This class was generated by Apache CXF 3.1.4 2016-04-01T17:56:26.268+08:00
 * Generated source version: 3.1.4
 * 
 */

@javax.jws.WebService(serviceName = "SendMsgServiceSubscribeService", portName = "SendMsgServiceSubscribeServiceHttpPort", targetNamespace = "http://cctv.com/ESB/service/SendMsgServiceSubscribeService/1.0", endpointInterface = "com.cctv.esb._interface.sendmsgservicesubscribeservice._1_0.SendMsgServiceSub")
public class SendMsgServiceSubscribeServiceHttpPortImpl implements SendMsgServiceSub {

	private static final Logger LOG = Logger.getLogger(SendMsgServiceSubscribeServiceHttpPortImpl.class.getName());

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * com.cctv.esb._interface.sendmsgservicesubscribeservice._1_0.SendMsgServiceSub
	 * #subscribe(com.cctv.esb.schema.messagehead._0.RequestHeadType requestHead
	 * ,)com.cctv.mcs.schema.sendmsgservice._1.SendMsgServiceRequestType
	 * sendMsgServiceRequest )*
	 */
	public com.cctv.esb.schema.pubsub._1.ResponseType subscribe(com.cctv.esb.schema.messagehead._0.RequestHeadType requestHead,
			com.cctv.mcs.schema.sendmsgservice._1.SendMsgServiceRequestType sendMsgServiceRequest) {
		LOG.info("Executing operation subscribe");
		System.out.println(requestHead);
		System.out.println(sendMsgServiceRequest);
		MsgReq msgReq = null;
		ReqWorkflow reqWorkflow = null;
		ReqCommonmsg reqCommonmsg = null;
		ReqMamdownload reqMamdownload = null;
		ReqSystemerror reqSystemerror = null;
		ReqProbroadcast reqProbroadcast = null;
		ReqMeetingnotice reqMeetingnotice = null;
		EntityClassSet entityClassSet = new EntityClassSet();
		com.cctv.esb.schema.pubsub._1.ResponseType _return = null;
		ReqTaskService reqTaskService = ContextHolder.getBean(ReqTaskService.class);  //获得service
		String msgType = sendMsgServiceRequest.getMsgType();
		MsgContentType msgContentType = sendMsgServiceRequest.getMsgContent();
		long key = Long.valueOf(reqTaskService.createSequence("S_REQ_ID"));
		msgReq = entityClassSet.setMsgReq(sendMsgServiceRequest);
		msgReq.setZReqId(key);
		try {
			if (StringUtils.equals(msgType, "1")) {
				reqMeetingnotice = new ReqMeetingnotice();
				MeetingNoticeType meetingNoticeType = msgContentType.getMeetingNotice();
				reqMeetingnotice.setZContactinformation(meetingNoticeType.getContactInformation());
				reqMeetingnotice.setZMeetdescribe(meetingNoticeType.getMeetDescribe());
				reqMeetingnotice.setZMeetingcontacts(meetingNoticeType.getMeetingContacts());
				reqMeetingnotice.setZMeetingdate(meetingNoticeType.getMeetingDate().toGregorianCalendar().getTime());
				reqMeetingnotice.setZMeetingparticipant(meetingNoticeType.getMeetingParticipant());
				reqMeetingnotice.setZMeetingposition(meetingNoticeType.getMeetingPosition());
				reqMeetingnotice.setZMeetingtime(meetingNoticeType.getMeetingTime().toGregorianCalendar().getTime());
				reqMeetingnotice.setZMeetingtopic(meetingNoticeType.getMeetingTopic());
				reqMeetingnotice.setZMsgid(meetingNoticeType.getMsgID());
				reqMeetingnotice.setZSenddepartment(meetingNoticeType.getSendDepartment());
				reqMeetingnotice.setCreateTimestamp(new Date());
				reqMeetingnotice.setZReqId(key);
				// 保存数据包到数据库的表中
				int ret = reqTaskService.saveMeetingNotice(msgReq,reqMeetingnotice);
				if (ret == 0) {
					_return = ResponseType.OK;// 操作成功!
				} else
					_return = ResponseType.FAIL; // 操作失败!
			} else if (StringUtils.equals(msgType, "2")) {
				reqWorkflow = new ReqWorkflow();
				StringBuffer stringBuffer = new StringBuffer();
				WorkFlowType workFlowType = msgContentType.getWorkFlow();
				reqWorkflow.setZContent(workFlowType.getContent());
				String docuId = workFlowType.getDocumentID();  //记录文档类型
				reqWorkflow.setZDocumentid(docuId == null ? null : Long.valueOf(docuId));
				reqWorkflow.setZDocumenttype(workFlowType.getDocumentType());
				reqWorkflow.setZLastuser(workFlowType.getLastUser());
				reqWorkflow.setZMsgid(workFlowType.getMsgID());
				reqWorkflow.setZMsgtopic(workFlowType.getMsgTopic());
				reqWorkflow.setZWorkflowstatus(workFlowType.getWorkFlowStatus());
				List<String> list = workFlowType.getWorkFlowUsers().getWorkFlowUser();
				int size = list.size();
				for (int i = 0; i < size; i++) {
					stringBuffer.append(list.get(i));
					if (i != size - 1) {   //最后一个名字后面不需要","号!
						stringBuffer.append(",");
					}
				}
				reqWorkflow.setZWorkflowusers(stringBuffer.toString());
				reqWorkflow.setZReqId(key);
				// 保存数据到数据库表中
				int ret = reqTaskService.saveWorkFlow(msgReq,reqWorkflow);
				if (ret == 0) {
					_return = ResponseType.OK;// 操作成功!
				} else
					_return = ResponseType.FAIL; // 操作失败!
			} else if (StringUtils.equals(msgType, "3")) {
				reqProbroadcast = new ReqProbroadcast();
				ProBroadcastType proBroadcastType = msgContentType.getProBroadcast();
				reqProbroadcast.setZColumncode(proBroadcastType.getColumnCode());
				reqProbroadcast.setZColumnname(proBroadcastType.getColumnName());
				reqProbroadcast.setZContent(proBroadcastType.getContent());
				reqProbroadcast.setZMsgid(proBroadcastType.getMsgID());
				reqProbroadcast.setZMsgtopic(proBroadcastType.getMsgTopic());
				reqProbroadcast.setZNodecode(proBroadcastType.getNodeCode());
				reqProbroadcast.setZNodename(proBroadcastType.getNodeName());
				reqProbroadcast.setZProgramcode(proBroadcastType.getProgramCode());
				reqProbroadcast.setZProgramname(proBroadcastType.getProgramName());
				reqProbroadcast.setZStatustype(proBroadcastType.getStatusType());
				reqProbroadcast.setZReqId(key);
				// 保存数据到数据库表中
				int ret = reqTaskService.saveProBroadcast(msgReq,reqProbroadcast);
				if (ret == 0) {
					_return = ResponseType.OK;// 操作成功!
				} else
					_return = ResponseType.FAIL; // 操作失败!
			} else if (StringUtils.equals(msgType, "4")) {
				reqMamdownload = new ReqMamdownload();
				MAMDownloadType mamDownloadType = msgContentType.getMAMDownload();
				reqMamdownload.setZContent(mamDownloadType.getContent());
				reqMamdownload.setZDownloadapply(mamDownloadType.getDownloadApply());
				reqMamdownload.setZMsgid(mamDownloadType.getMsgID());
				reqMamdownload.setZMsgtopic(mamDownloadType.getMsgTopic());
				String downType = mamDownloadType.getNextNodeID();  //记录加载类型id
				reqMamdownload.setZNextnodeid(downType == null ? null : Long.valueOf(downType));
				reqMamdownload.setZNextnodename(mamDownloadType.getNextNodeName());
				reqMamdownload.setZReqId(key);
				// 保存数据到数据库表
				int ret = reqTaskService.saveMAMDownload(msgReq,reqMamdownload);
				if (ret == 0) {
					_return = ResponseType.OK;// 操作成功!
				} else
					_return = ResponseType.FAIL; // 操作失败!
			} else if (StringUtils.equals(msgType, "5")) {
				reqSystemerror = new ReqSystemerror();
				SystemErrorType systemErrorType = msgContentType.getSystemError();
				String errorType = systemErrorType.getErrorSystemID();//记录错误系统id
				reqSystemerror
						.setZErrorsystemid(errorType == null ? null : Long.valueOf(errorType));
				reqSystemerror.setZMsgid(systemErrorType.getMsgID());
				reqSystemerror.setZReqId(key);
				// 保存数据到数据库表中
				int ret = reqTaskService.saveSystemError(msgReq,reqSystemerror);
				if (ret == 0) {
					_return = ResponseType.OK;// 操作成功!
				} else
					_return = ResponseType.FAIL; // 操作失败!
			} else if (StringUtils.equals(msgType, "6")) {
				reqCommonmsg = new ReqCommonmsg();
				CommonMsgType commonMsgType = msgContentType.getCommonMsg();
				reqCommonmsg.setZContent(commonMsgType.getContent());
				String msgId = commonMsgType.getMsgID();  //记录消息id
				reqCommonmsg.setZMsgid(msgId == null ? null : Long.valueOf(msgId));
				reqCommonmsg.setZMsgtopic(commonMsgType.getMsgTopic());
				reqCommonmsg.setZReqId(key);
				// 保存数据到数据库的表中
				int ret = reqTaskService.saveCommonMsg(msgReq,reqCommonmsg);
				if (ret == 0) {
					_return = ResponseType.OK;// 操作成功!
				} else
					_return = ResponseType.FAIL; // 操作失败!
			}
			return _return;
		} catch (java.lang.Exception ex) {
			ex.printStackTrace();
			throw new RuntimeException(ex);
		}
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * com.cctv.esb._interface.sendmsgservicesubscribeservice._1_0.SendMsgServiceSub
	 * #getServiceInfo(com.cctv.esb.schema.monitor._0.GetServiceInfoRequestType
	 * getServiceInfoRequest )*
	 */
	public com.cctv.esb.schema.monitor._0.GetServiceInfoResponseType getServiceInfo(
			com.cctv.esb.schema.monitor._0.GetServiceInfoRequestType getServiceInfoRequest) {
		LOG.info("Executing operation getServiceInfo");
		System.out.println(getServiceInfoRequest);
		try {
			com.cctv.esb.schema.monitor._0.GetServiceInfoResponseType _return = null;
			return _return;
		} catch (java.lang.Exception ex) {
			ex.printStackTrace();
			throw new RuntimeException(ex);
		}
	}
}
